package com.woniuxy.demo.epai.controller;


import com.woniuxy.demo.epai.common.Result;
import com.woniuxy.demo.epai.controller.component.ControllerBase;
import com.woniuxy.demo.epai.controller.form.MypageForm;
import com.woniuxy.demo.epai.controller.form.ProductForm;
import com.woniuxy.demo.epai.controller.form.ProductSaleForm;
import com.woniuxy.demo.epai.model.Product;
import com.woniuxy.demo.epai.service.IProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 拍品表 前端控制器
 * </p>
 *
 * @author epai
 * @since 2021-04-12
 */
@RestController
@RequestMapping("/epai/product")
@Slf4j
public class ProductController extends ControllerBase {

    @Autowired
    private IProductService iProductService;

    @GetMapping("/find")
    public Result find(MypageForm pageForm,ProductForm productForm){
        log.info("接收查询条件{},{},{}",productForm.getClassify(),productForm.getP_list(),productForm.getS_list());
        MypageForm<Product> mypageForm = iProductService.queryProductByTerm(pageForm, productForm);
        return Result.success(mypageForm);
    }

    @PostMapping("/addProduct")
    public Result addProduct(@RequestBody ProductSaleForm form){
        log.info("进入方法,参数为,{},{}");
        Product product = new Product();
        product.setUid(1);
        product.setProductName(form.getProductName());
        product.setCid(form.getCid());
        product.setImage(form.getImage());
        product.setMode(form.getMode());
        product.setIntroduce(form.getIntroduce());
        product.setStatus("NO");
        product.setParId(form.getParId());
        int i = iProductService.addProduct(product);
        int id = product.getId();
        if(i == 1){
            return Result.success(id);
        }else {
            return Result.fail("发布失败");
        }

    }


}

